package com.lyx.blogspace.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyx.blogspace.admin.convert.BlogSettingsConvert;
import com.lyx.blogspace.admin.model.vo.blogsettings.FindBlogSettingsRspVO;
import com.lyx.blogspace.admin.model.vo.blogsettings.UpdateBlogSettingsReqVO;
import com.lyx.blogspace.admin.service.AdminBlogSettingsService;
import com.lyx.blogspace.common.domain.dos.BlogSettingsDO;
import com.lyx.blogspace.common.domain.mapper.BlogSettingsMapper;
import com.lyx.blogspace.common.utils.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author by lyx
 */
@Service
@Slf4j
public class AdminBlogSettingsServiceImpl extends ServiceImpl<BlogSettingsMapper, BlogSettingsDO> implements AdminBlogSettingsService {
    @Autowired
    private BlogSettingsMapper blogSettingsMapper;
    @Override
    public Response updateBlogSettings(UpdateBlogSettingsReqVO updateBlogSettingsReqVO) {
//        BlogSettingsDO blogSettingsDO = BlogSettingsDO.builder()
//            .id(1L)
//            .name(updateBlogSettingsReqVO.getName())
//            .introduction(updateBlogSettingsReqVO.getIntroduction())
//            .author(updateBlogSettingsReqVO.getAuthor())
//            .logo(updateBlogSettingsReqVO.getLogo())
//            .csdnHomepage(updateBlogSettingsReqVO.getCsdnHomepage())
//            .giteeHomepage(updateBlogSettingsReqVO.getGiteeHomepage())
//            .githubHomepage(updateBlogSettingsReqVO.getGithubHomepage())
//            .zhihuHomepage(updateBlogSettingsReqVO.getZhihuHomepage())
//            .build();
        // 使用 mapstruct
        BlogSettingsDO blogSettingsDO = BlogSettingsConvert.INSTANCE.convertVO2DO(updateBlogSettingsReqVO);
        blogSettingsDO.setId(1L);
        saveOrUpdate(blogSettingsDO);
        return Response.success();
    }

    /**
     * 获取博客设置详情
     *
     * @return
     */
    @Override
    public Response findDetail() {
        // 查询 ID 为 1 的记录
        BlogSettingsDO blogSettingsDO = blogSettingsMapper.selectById(1L);

        // DO 转 VO
        FindBlogSettingsRspVO vo = BlogSettingsConvert.INSTANCE.convertDO2VO(blogSettingsDO);

        return Response.success(vo);
    }
}
